import requests
from lxml import etree
import pandas as pd

response = requests.get("https://www.lgfdcw.com/cs/")


html = etree.HTML(response.content.decode(encoding="gbk"))  # 将HTML页面代码转换为etree

# //a[@target="_blank"]/strong
# adress_list =  html.xpath("//a[@target='_blank']/strong")
tr_list = html.xpath("//tr[@bgcolor='#FFFFFF']")

houses = []

for tr in tr_list:
    house = {}
    house["详细信息"] = tr.xpath("td/a/strong/text()")
    house["面积"] = tr.xpath("td/text()")[0]
    house["登记时间"] = tr.xpath("td/text()")[1]
    house["出售价格"] = tr.xpath("td/font/text()")
    house["区域"] = tr.xpath("td/a/text()")[0]
    house["房型"] = tr.xpath("td/a/text()")[1]
    house["户型"] = tr.xpath("td/a/text()")[2]
    houses.append(house)

df = pd.DataFrame(houses,columns=["详细信息","面积","登记时间","出售价格","区域","房型","户型"])
df.to_csv("龙港房产楼盘出售信息.scv")



